// pages/classic/classic.js
// import {HTTP} from "../../util/http.js"
import {
  ClassicModel
} from "../../models/classic.js"
import {
  LikeModel
} from "../../models/like.js"
let classicModel = new ClassicModel(); //注意这里是实例化的，要使用这个
let likeModel = new LikeModel();
let setformatDate =require("../../util/date.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    test: 1,
    classicData: null,
    latest: true,
    first: false,
    likeCount:0,
    likeStatus:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let se = 1533793467;
      var sa = 1398250549490;
      var timeSet =new Date(sa);
   
   var x=  setformatDate.formatDate(timeSet)
   console.log(x)
    classicModel.getLatest((res) => {
      // this._getLIkeStatus(res.id,res.type)

      this.setData({
        classicData: res,
        likeCount:res.fav_nums,
        likeStatus:res.like_status
      })
    })
  },
  onLike(event) {
  
    let behavier = event.detail.behavior;
    likeModel.like(behavier, this.data.classicData.id, this.data.classicData.type)
  },
  onLeft(event) {
    this._upadteClassic('next')
  },
  onRight(event) {
    this._upadteClassic("previous")
  },
  _upadteClassic(nextorpre) {
    let index = this.data.classicData.index
    classicModel.getClassic(index, nextorpre, (res) => {
     
      this._getLIkeStatus(res.id,res.type)
      this.setData({
        classicData: res,
        latest: classicModel.islatest(res.index),
        first: classicModel.isfirst(res.index)
      })

    })
  },
  _getLIkeStatus(artid,categry) {
    likeModel.getClaslikeStatus(artid,categry,(res) =>{
      this.setData({
        likeCount:res.fav_nums,
        likeStatus:res.like_status
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})